package com.arunsk.log4metrics.level;

import org.apache.log4j.Level;

public class Metrics extends Level {

	private static final long serialVersionUID = 7637694118027572524L;

	static public final int METRIC_INT = (Level.DEBUG_INT + Level.INFO_INT) / 2;

	private static String METRIC_STR = "METRIC";

	public static final Metrics METRIC = new Metrics(METRIC_INT, METRIC_STR, 7);

	protected Metrics(int level, String levelStr, int syslogEquivalent) {
		super(level, levelStr, syslogEquivalent);
	}

	public static Level toLevel(String sArg) {
		return (Level) toLevel(sArg, Metrics.METRIC);
	}

	public static Level toLevel(int i) throws IllegalArgumentException {
		switch (i) {
		case METRIC_INT:
			return Metrics.METRIC;
		}
		
		return Level.toLevel(i);
	}

	public static Level toLevel(String sArg, Level defaultValue) {

		if (sArg == null) {
			return defaultValue;
		}
		String stringVal = sArg.toUpperCase();

		if (stringVal.equals(METRIC_STR)) {
			return Metrics.METRIC;
		}

		return Level.toLevel(sArg, (Level) defaultValue);
	}
}
